﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcDDshop2.Controllers
{
    public class DetailController : Controller
    {
        //
        // GET: /Detail/

        public ActionResult Detail( int id )
        {
            Book book = BLL.Bll.book_id(id);
            ViewBag.book = book;
            Book b = BLL.Bll.book_id(72);
            ViewBag.b = b;
            List<Ping> pings = BLL.Bll.select_ping(id);
            ViewBag.pings = pings;
            return View();
        }

        //评论功能
        [HttpPost]
        public ActionResult ping(string a)
        {
            int bookid = Convert.ToInt32(Request["book"]);
            int userid = Convert.ToInt32(Session["userid"]);
            string ping = Request["ping"].ToString();
            string dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            BLL.Bll.insert_ping(bookid, userid, ping, dt);
            return RedirectToAction("Detail", "Detail", new { id = bookid });
        }

        public ActionResult shou(int id)
        {
            if (Session["userid"] == null)
            {
                return RedirectToAction("Login", "Login");
            }
            else
            {
                int userid = Convert.ToInt32(Session["userid"]);
                bool i = BLL.Bll.insert_shou(id, userid);
                return RedirectToAction("Detail", "Detail", new { id = id });
            }
        }            

        public ActionResult delect_shou( int id)
        {
            int userid = Convert.ToInt32(Session["userid"]);
            BLL.Bll.delete_shou(id,userid);
            return RedirectToAction("Info","Info");
        }
    }
}
